package com.csii.adhoc.controller.board;

import com.csii.adhoc.annotation.OperationLog;
import com.csii.adhoc.board.BoardVo;
import com.csii.adhoc.board.service.BoardService;
import com.csii.adhoc.util.DateUtils;
import com.csii.result.APIResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Optional;

/**
 * @description: 仪表盘控制层
 * @author: panChuanJiang
 * @create: 2021-02-03 13:44
 */
@Slf4j
@RestController
@RequestMapping("board")
public class BoardController {
    @Resource
    private BoardService boardService;

    @RequestMapping("saveBoardInfo")
    @OperationLog("仪表盘维护")
    public APIResult saveBoardInfo(@RequestBody BoardVo vo){
        String userId = Optional.ofNullable(String.valueOf(SecurityUtils.getSubject().getPrincipal())).orElse("未知用户");
        vo.setUpdatedBy(userId)
                .setUpdatedDt(DateUtils.getDateString("yyyyMMddHHmmss"));
        boardService.boardMaintain(vo, vo.getOptMode());
        return APIResult.successResult(null);
    }

    @RequestMapping("selectListBoard")
    public APIResult selectListBoard(@RequestBody(required = false) BoardVo vo){
        return APIResult.successResult(boardService.selectListBoard(vo));
    }

}
